#!/bin/sh
# - item

. $LKP_SRC/lib/env.sh
. $LKP_SRC/lib/debug.sh
. $LKP_SRC/lib/reproduce-log.sh
. $LKP_SRC/lib/upload.sh
. $LKP_SRC/lib/perf_file_system.sh


yum -y install make numactl gcc-gfortran libnsl tar gcc-c++ wget
mk_fs_mount "/test"


mkdir /test/cpu2017 /test/cpu2017-1.0.2
cd /test
wget https://api.compass-ci.openeuler.org:20009/os/install/performance_tools/speccpu20173ci.tar.gz
tar zxvf speccpu20173ci.tar.gz

chown -R root:root speccpu2017
chown root:root cpu2017-1.0.2.iso
mount -o loop /test/cpu2017-1.0.2.iso /test/cpu2017
cp -r /test/cpu2017/* /test/cpu2017-1.0.2/
chmod -R 755 /test/cpu2017-1.0.2/
cd /test/cpu2017-1.0.2
echo yes | bash ./install.sh


if [ $item == "fpspeed" ]; then
    echo "GOMP_CPU_AFFINITY=0-`expr $(cat /proc/cpuinfo |grep processor|wc -l) - 1`">>$LKP_SRC/env/emulate-login-env
fi

cd /test/speccpu2017
log_cmd use_benchmark_env bash ./cpu2017-test.sh $item

start_line=$(echo $(cat -n /test/cpu2017-1.0.2/result/CPU2017*.txt|grep '================'|head -n 1|awk '{print $1}')|awk '{print $1 + 1}')
end_line=$(echo $(cat -n /test/cpu2017-1.0.2/result/CPU2017*.txt|grep ' Est. SPEC'|head -n 1|awk '{print $1}'))
sed -n "${start_line},${end_line}p" /test/cpu2017-1.0.2/result/CPU2017*.txt|grep -v ' Est. SPEC'|awk '{printf $1 " " $4"\n"}' >$TMP_RESULT_ROOT/speccpu-2017
sed -n "${start_line},${end_line}p" /test/cpu2017-1.0.2/result/CPU2017*.txt|grep ' Est. SPEC'|awk '{printf $1  $2 " " $3"\n"}' >>$TMP_RESULT_ROOT/speccpu-2017
upload_files -t results /test/cpu2017-1.0.2/result/*


